package cn.springcloud.fix.demo.leecode;

public class Test09 {

    public static void main(String[] args) {
        //String res = getMaxString("abrcd", "rabcdee");
        //System.out.println(res);
    }

    private static String getMaxString(String min, String max) {
        for (int i = 0; i < min.length(); i++) {
            for (int j = min.length() - i; j >= 0; j--) {
                String str = min.substring(0, j);
                if (max.contains(str)) {
                    return str;
                }
            }
        }
        return null;
    }

    private static String getMax(String a, String b) {
        String max = a.length() > b.length() ? a : b;
        String min = a.length() > b.length() ? b : a;

        for (int i = 0; i < min.length(); i++) {
            int subLen = min.length() - i;
            int endStep = min.length() - subLen;

            for (int j = 0; j <= endStep; j++) {
                int endIndex = j + subLen;
                String str = min.substring(j, endIndex);
                if (max.contains(str)) {
                    return str;
                }
            }
        }
        return null;
    }
}
